Skip to content

Speed up the merge filter and the include and embed tags with variables - #5029

Open
Kocal wants to merge 1 commit into
twigphp:3.xfrom
Kocal:perf/merge-single-pass
Open

Kocal wants to merge 1 commit into
twigphp:3.xfrom
Kocal:perf/merge-single-pass

Conversation

@Kocal

@Kocal Kocal commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

CoreExtension::merge() merged its arguments two by two and copied an intermediate array each time. With {% include ... with {...} %}, that intermediate array is the whole context.

It now validates the arguments and calls array_merge() once. Errors are unchanged.

A context of 35 variables + 3 variables goes from 435-485 -> 269-293 ns, and two 3-variable arrays from 299-372 -> 144-153 ns.

…ariables

`CoreExtension::merge()` merged its arguments two by two and copied an intermediate array each time. With `{% include ... with {...} %}`, that intermediate array is the whole context.

It now validates the arguments and calls `array_merge()` once. Errors are unchanged.

A context of 35 variables + 3 variables goes from 435-485 -> 269-293 ns, and two 3-variable arrays from 299-372 -> 144-153 ns.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants